<%@page import="com.wanmait.hotelManage.vo.NewsComment"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.text.DateFormat"%>
<%@page import="com.wanmait.hotelManage.vo.News"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%String path = request.getContextPath();
    	News n=(News)request.getAttribute("ne");
    	ArrayList<NewsComment>nc=(ArrayList<NewsComment>)request.getAttribute("newsComment");
    	Integer rows=(Integer)request.getAttribute("rows");
    	Integer id=(Integer)request.getAttribute("id");
    %>
<jsp:include page="/inc/header.jsp"></jsp:include>
    <!-- main header area end -->

     <!--中标题-->
    <section class="page-title text-center">
        <div class="auto-container">
            <div class="content-box">
                <div class="title">新闻详情</div>
                <ul class="bread-crumb">
                    <li><a href="<%=path%>">首页<i class="fa fa-angle-right"></i></a></li>
                    <li>新闻详情</li>
                </ul>
            </div>
        </div>
    </section>
    <!--End Page Title-->

    <!-- News Details -->
    <section class="sidebar-page-container news-details news-section latest-news">
        <div class="container">
            <div class="row">
                <div   style="margin-left: 200px;" class="content-side col-md-8 col-sm-8 col-xs-12">
                   	<!--左边全部-->
                    <div class="blog-single-section">
                    <% 
                    if(n!=null){
                    	DateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    	String inputTime=df.format(n.getInputTime());
                    	%>
                        <div class="single-item">
                            <div class="img-box">
                                <figure><img src="<%=path%>/static/images/news/<%=n.getPic() %>" alt=""></figure>
                            </div>
                            <div class="news-content">
                                <h3><%=n.getTitle() %></h3>
                                <span style="margin-left:333px"><%=inputTime %></span>
                            </div>
                            <p><%=n.getContent() %></p>
                        </div>
                        <%
                    }
                        %>
                        <!-- <div class="post-share-option">
                            <div class="text">标签</div>
                            <ul class="post-social">
                                <li>分享:</li>
                                <li><a href="#"><i class="fa fa-facebook"></i></a></li>
                                <li><a href="#"><i class="fa fa-twitter"></i></a></li>
                                <li><a href="#"><i class="fa fa-pinterest-p"></i></a></li>
                                <li><a href="#"><i class="fa fa-vimeo"></i></a></li>
                            </ul>
                        </div> -->
                        	   <!--所有评论-->
                        <div class="comment-area">
                            <div class="comment-title"><h3>评论 (<%=rows %>)</h3></div>
<%!
//递归  方法  显示评论的所有的子评论
public void showComment(NewsComment comment,JspWriter out)throws Exception
{
	out.println("<li>");
	
	//显示parent	
	String name = "";
	if(comment.getNewsComment()!=null)
	{
		name = comment.getNewsComment().getUserinfo().getUsername();
		DateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String inputTime=df.format(comment.getInputTime());
		out.println("<h3>"+comment.getUserinfo().getUsername()+"回复"+name+"说:"+comment.getContent()+"</h3>");
		out.println("<a id='spana' data-id='"+comment.getId() +"'class='ac' href='javascript:void(0)'>举报</a>");
		out.println("<a id='span' data-name='"+comment.getUserinfo().getUsername() +"' data-id='"+comment.getId() +"'class='space' href='javascript:void(0)'>回复</a>");
		out.println("<span class='spaninput'>"+inputTime+"</span>");
	}else{
		DateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String inputTime=df.format(comment.getInputTime());	
	out.println("<h3>"+comment.getUserinfo().getUsername()+name+"说:"+comment.getContent()+"</h3>");	
	out.println("<a id='spana' data-id="+comment.getId()+" class='ac' href='javascript:void(0)'>举报</a>");
	out.println("<a id='span' data-name='"+comment.getUserinfo().getUsername() +"' data-id='"+comment.getId() +"'class='space' href='javascript:void(0)'>回复</a>");
	out.println("<span class='spaninput'>"+inputTime+"</span>");
	}
	//显示parent的children
	ArrayList<NewsComment> children = comment.getChildren();//获得parent的子评论
	out.println("<ul>");
	for(NewsComment child:children)
	{
		this.showComment(child,out);
	}
	out.println("</ul>");
	
	out.println("</li>");
}
%>
<ul>
	<%
	for(NewsComment comment:nc)//循环的一级评论
	{
		this.showComment(comment,out);
	}
	%>
</ul>
                          <%--   <div class="comment-box">
                                <figure><img src="<%=path%>/static/images/news/comment-1.png" alt=""></figure>
                                <div class="comment-inner">
                                    <div class="comment-name">Jessica Brown</div>
                                    <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudant tota rem ape riamipsa eaque  quae nisi ut aliquip commodo consequat. </p>
                                </div>
                            </div> --%>
                            
                        </div>
                        	   <!--发表评论-->
                        <div class="comment-form">
                            <div class="comment-title"><h3>发表评论</h3></div>
                            <form id="contact-form" name="contact_form" class="default-form" action="inc/sendmail.php" method="post">
                                <div class="row">
                                <div class="col-md-6 col-sm-6 col-xs-12">
                                        <input type="text" id="text" data-id="" name="form_name" value="">
                                    </div> 
                                    <a id="closea">清除回复人</a>
                                    <div class="col-md-12 col-sm-12 col-xs-12">
                                        <textarea name="form_message" id="textare" ></textarea><span id="spantextarea"></span>
                                    </div>
                                    <!-- <div class="col-md-6 col-sm-6 col-xs-12">
                                        <input type="email" name="form_email" value="" placeholder="Your Email" required="">
                                    </div> -->
                                </div>
                                <button type="button" class="btn-one" data-loading-text="Please wait...">提交</button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
    <!-- News Details end -->

    <!-- 底部 -->
    <!-- 底栏 -->
<jsp:include page="/inc/footer.jsp"/>
    <!-- main footer area end -->
    <style>
    #spantextarea{
    color:red;
    }
    .spaninput{
    float:right;
    }
    </style>
    <script>
    $("#closea").click(function(){
    	 $("#text").val("");
		 $("#text").data("id",0);
    })
    $("#text").click(function(){
        $("#text").attr("disabled","disabled");
    })
    </script>
    <script>
    $(function(){
    	$(".ac").click(function(){
     	   var a=window.prompt("请输入举报原因");
			 if(!a){
				 return false;
			 }
			 var id=$(this).data("id");
			 $.ajax({
				 url:"<%=path%>/NewsListServlet?action=de",
					 data:{id:id,a:a},
						 success:function(msg){
							 if(msg=="ok"){
						 alert("举报成功,请等待管理员审批")
					 }else if(msg=="no"){
						 window.location.href="<%=path%>/login.jsp";
					 }
						 }
			 })
		 })
		 $(".space").click(function(){
			 var id=$(this).data("id");
			 var name=$(this).data("name");
			 $("#text").val(name);
			 $("#text").data("id",id);
		 })
		 $(".btn-one").click(function(){
			 var text=$("#text").val();
			 var texti=$("#text").data("id");
			  var textare=$("#textare").val();
			 if(text.length==0||texti.length==0){
				 texti=0;
			 } 
			 if(textare.length<6){
				 $("#spantextarea").html("少于六个字");
				 return false;
			 }else{
				 $("#spantextarea").html("");
			 }
			 $.ajax({
				 url:"<%=path%>/NewsListServlet?action=insert&id=<%=id%>",
				 data:{texti:texti,textare:textare},
				 success:function(msg){
					 if(msg=="ok"){
						 window.location.href="<%=path%>/NewsListServlet?action=search&id=<%=id%>";
					 }else if(msg=="no"){
						 window.location.href="<%=path%>/login.jsp";
					 } 
				 }
			 })
		 })
    })
    </script>